hysop.core.memory.mempool module

class hysop.core.memory.mempool.MemoryPool(name, allocator, max_alloc_bytes=None, mantissa_bits=4, verbose=None, **kwds)[source]

Bases: object

pyopencl/pycuda like memory pool extended to be compatible for all backends.

Builds a MemoryPool from an allocator. Provides an allocator like interface.

Parameters:
  • name (str) – the name of this allocator for logging purposes

  • allocator (hysop.core.memory.AllocatorBase) – allocator used by this memory pool, must be an immediate allocator.

  • verbose (bool) – turn on or off allocator messages (defaults to hysop verbosity configuration)

  • max_alloc_bytes (int) –

    maximum number of bytes this pool will try to allocate before raising a MemoryError. default value is:

    -80% of physical host memory if allocator is a HostAllocator. -None (no limit) if allocator is a DeviceAllocator

  • mantissa_bits (int) – subdivisions bits of power of two allocations. higher values means more bins (less memory waste) but less buffer reuse.

Notes

An allocator that fails to allocate memory should raise a MemoryError to expect the pool to work correctly.

Some allocators may fail to raise a MemoryError when there is no more memory left and will just trigger a SIGKILL from operating system or deadlock instead. To avoid such situations, put an artificial software allocation imit trough the max_alloc_bytes parameter. Exceeding this allocation limit will throw a proper MemoryError.

Examples:

*Host allocation on ubuntu 16.04 => SIGKILL *OpenCl AMD mesa open source driver on ubuntu 16.04 => deadlock *OpenCl Nvidia 375.20 driver on ubuntu 16.04 => work as expected

__call__(nbytes, alignment=None)

Allocate a buffer of size nbytes and given alignment. The real size of the allocated buffer may be greater and wasted memory mostly depend on configured mantissa_bits (default is 2). The returned buffer is an instance of hysop.core.memory.buffer.PooledBuffer. While a reference to the returned object is kept, it won’t return to the pool.

alloc_size(bin_nr)[source]

Compute real allocation size given an bin number. Note that alloc_size(bin_number(x)) is always >= x.

allocate(nbytes, alignment=None)[source]

Allocate a buffer of size nbytes and given alignment. The real size of the allocated buffer may be greater and wasted memory mostly depend on configured mantissa_bits (default is 2). The returned buffer is an instance of hysop.core.memory.buffer.PooledBuffer. While a reference to the returned object is kept, it won’t return to the pool.

allocate_aligned(size, alignment)[source]

Same as allocate for a memory pool.

allocation_report()[source]

Returns various statistics of this pool as a string.

bin_number(size)[source]

Returns the bin number in witch a buffer of given size would be put.

free(buf, size)[source]
free_held()[source]

Free all unused held buffers but does not set the stop_holding_flag flag.

header()[source]

Return the header of this pool for logging purposes.

property held_blocks

Returns the number of held blocks.

may_alloc(size)[source]

Return true if this pool may allocate a buffer of given size (in bytes). Only logical bound is checked (max_alloc_bytes).

print_allocation_report()[source]

Print various statistics of this pool.

stop_holding()[source]

Tells the pool to stop holding back freed buffer and direclty free all unused buffers.

class hysop.core.memory.mempool.PoolAllocationStatistics[source]

Bases: object

mean_alloc_time()[source]
mean_free_time()[source]
push_alloc(size, t)[source]
push_free(size, t)[source]
push_return(size)[source]
push_reuse(size)[source]
reuse_factor()[source]